package com.example.todolist.Hilt

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import com.example.todolist.database.DAO.CategoryDao
import com.example.todolist.database.DAO.TodoDao
import com.example.todolist.database.Mydatabase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {
    private const val DATABASE_NAME = "todoApp_db.db"

    @Provides
    @Singleton
    fun provideDatabase(@ApplicationContext context: Context): Mydatabase {
        return Room.databaseBuilder(
            context.applicationContext,
            Mydatabase::class.java,
            DATABASE_NAME
        )
            .fallbackToDestructiveMigration()
            .build()
    }

    @Provides
    fun getTodoDao(database: Mydatabase): TodoDao {
        return database.getTodoDao()
    }

    @Provides
    fun getCategoryDao(database: Mydatabase): CategoryDao {
        return database.getCategoryDao()
    }

}